﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
//using AssemblyCSharp;
using System.Text;
using System.Security.Cryptography;
using System;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Runtime.InteropServices;

public class ShowCoachInfo : MonoBehaviour {

    public Text tipInfo;
    public InputField inputId;
    public InputField inputUserName;
    public InputField inputProductId;
    public InputField tipUserInfo;
    public GameObject modifyBtnPlane;
    public GameObject modifyName;
    public GameObject modifyPhone;
    public GameObject modifyCompany;
    public GameObject modifyAddress;
    public InputField inputName;
    public InputField inputPhone;
    public InputField inputCompany;
    public InputField inputAddress;
    DataSet ds;
    string productId;
    public string s1;
    public string s2;
    public string s3;
    public string s4;
    public string s5;
    public string s6;
    public string s7;
    public string s30;
    public string s8;
    public string s9;
    public string s10;
    public string s11;
    public string s12;
    public string s13;
    public string s14;
    public string s15;
    public string s16;
    public string s17;
    public string s18;
    public string s19;
    public string s20;
    public string s21;
    public string s22;
    public string s23;
    public string s24;
    public string s25;
    public string s26;
    public string s27;
    public string s28;
    public string s29;
    public string s31;
    public string s32,s33,s34,s35,s36,s37;

    void Start()
    {
        modifyBtnPlane.SetActive(false);
        modifyName.SetActive(false);
        modifyPhone.SetActive(false);
        modifyCompany.SetActive(false);
        modifyAddress.SetActive(false);
    }

    void ShowInfo(string ss)
    {
        tipInfo.text = ss;
    }

    void SetData1()
    {
        //ds = SqlTool._instance.ExistOrNot(s2 + inputProductId.text + s3);
    }

    void SetData2()
    {
        if (ds.Tables[0].Rows.Count > 0)
        {
            productId = inputProductId.text;
            tipUserInfo.text = s35 + ds.Tables[0].Rows[0][0] + s36 + ds.Tables[0].Rows[0][1] + s4 + ds.Tables[0].Rows[0][4] + s5 + ds.Tables[0].Rows[0][5]
                               + s6 + ds.Tables[0].Rows[0][7] + s7 + ds.Tables[0].Rows[0][8]+ s30 + ds.Tables[0].Rows[0][10]+ s37 + ds.Tables[0].Rows[0][11];
            modifyBtnPlane.SetActive(true);
            tipInfo.text = "";
        }
        else
        {
            ShowInfo(s8);
        }
    }

    void SetData3()
    {
        //ds = SqlTool._instance.ExistOrNot(s9 + inputUserName.text + "'");
    }

    void SetData4()
    {
        if (ds.Tables[0].Rows.Count > 0)
        {
            productId = ds.Tables[0].Rows[0][1].ToString();
            tipUserInfo.text = s35 + ds.Tables[0].Rows[0][0] + s36 + ds.Tables[0].Rows[0][1] + s4 + ds.Tables[0].Rows[0][4] + s5 + ds.Tables[0].Rows[0][5]
                               + s6 + ds.Tables[0].Rows[0][7] + s7 + ds.Tables[0].Rows[0][8] + s30 + ds.Tables[0].Rows[0][10] + s37 + ds.Tables[0].Rows[0][11];
            modifyBtnPlane.SetActive(true);
            tipInfo.text = "";
        }
        else
        {
            ShowInfo(s10);
        }
    }

    void SetData5()
    {
        //ds = SqlTool._instance.ExistOrNot(s11 + productId + "'");
    }

    void SetData6()
    {
        //ds = SqlTool._instance.ExistOrNot(s33 + inputId.text + "'");
    }

    void SetData7()
    {
        if (ds.Tables[0].Rows.Count > 0)
        {
            productId = ds.Tables[0].Rows[0][1].ToString();
            tipUserInfo.text = s35 + ds.Tables[0].Rows[0][0] + s36 + ds.Tables[0].Rows[0][1] + s4 + ds.Tables[0].Rows[0][4] + s5 + ds.Tables[0].Rows[0][5]
                               + s6 + ds.Tables[0].Rows[0][7] + s7 + ds.Tables[0].Rows[0][8] + s30 + ds.Tables[0].Rows[0][10] + s37 + ds.Tables[0].Rows[0][11];
            modifyBtnPlane.SetActive(true);
            tipInfo.text = "";
        }
        else
        {
            ShowInfo(s10);
        }
    }
    public void CheckId()
    {
        if (inputId.text != "")
        {
            ShowInfo(s1);
            SetData6();
            SetData7();
        }
        else
        {
            ShowInfo(s34);
        }
    }

    public void CheckProductId()
    {
        if (inputProductId.text != "")
        {
            ShowInfo(s1);
            SetData1();
            SetData2();
        }
        else
        {
            ShowInfo(s12);
        }
    }

    public void CheckUserName()
    {
        if (inputUserName.text != "")
        {
            ShowInfo(s1);
            SetData3();
            SetData4();
        }
        else
        {
            ShowInfo(s13);
        }
    }

    void ShowInfo()
    {
        SetData5();
        tipUserInfo.text = s35 + ds.Tables[0].Rows[0][0] + s36 + ds.Tables[0].Rows[0][1] + s4 + ds.Tables[0].Rows[0][4] + s5 + ds.Tables[0].Rows[0][5]
                           + s6 + ds.Tables[0].Rows[0][7] + s7 + ds.Tables[0].Rows[0][8] + s30 + ds.Tables[0].Rows[0][10] + s37 + ds.Tables[0].Rows[0][11];
    }

    public void ModifyName()
    {
        modifyName.SetActive(true);
    }

    public void ModifyPhone()
    {
        modifyPhone.SetActive(true);
    }

    public void ModifyCompany()
    {
        modifyCompany.SetActive(true);
    }

    public void ModifyAddress()
    {
        modifyAddress.SetActive(true);
    }

    public void ModifyTime()
    {
        SubmitTime();
    }

    public void CleanUserInfo()
    {
        //SqlTool._instance.UpdateInto(s14, new string[] { s15 }, new string[] {s16}, s17, productId);
        ShowInfo(s18);
        tipUserInfo.text = "";
        modifyBtnPlane.SetActive(false);
    }

    public void SubmitName()
    {
        if (inputName.text != "")
        {
            //SqlTool._instance.UpdateInto(s14, new string[] { s15}, new string[] { inputName.text},s17, productId);
            ShowInfo(s19);
            inputName.text = "";
            modifyName.SetActive(false);
            ShowInfo();
            
        }
        else
        {
            ShowInfo(s20);
        }
    }

    public void SubmitPhone()
    {
        if (inputPhone.text.Length == 11)
        {
            //SqlTool._instance.UpdateInto(s14, new string[] { s21 }, new string[] { inputPhone.text }, s17, productId);
            ShowInfo(s22);
            inputPhone.text = "";
            modifyPhone.SetActive(false);
            ShowInfo();
            
        }
        else
        {
            ShowInfo(s23);
        }
    }

    public void SubmitCompany()
    {
        if (inputCompany.text != "")
        {
            //SqlTool._instance.UpdateInto(s14, new string[] { s24 }, new string[] { inputCompany.text }, s17, productId);
            ShowInfo(s25);
            inputCompany.text = "";
            modifyCompany.SetActive(false);
            ShowInfo();
           
        }
        else
        {
            ShowInfo(s26);
        }
    }

    public void SubmitAddress()
    {
        if (inputAddress.text != "")
        {
            //SqlTool._instance.UpdateInto(s14, new string[] { s27 }, new string[] { inputAddress.text }, s17, productId);
            ShowInfo(s28);
            inputAddress.text = "";
            modifyAddress.SetActive(false);
            ShowInfo();
           
        }
        else
        {
            ShowInfo(s29);
        }
    }

    public void SubmitTime()
    {
           // SqlTool._instance.UpdateInto(s14, new string[] { s31 }, new string[] { s16 }, s17, productId);
            ShowInfo(s32);
            ShowInfo();
    }


}
